package com.c5c7.Servlet;

import com.c5c7.dao.NoticeDao;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;

@WebServlet("/noticeDel.jsp")
public class NoticeDelServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String user = (String) req.getSession().getAttribute("User"); // 获取会话
        if (user == null || user.equals("")) {
            resp.sendRedirect("login.jsp");
            return;
        }
        int NoticeId = Integer.parseInt(req.getParameter("NoticeId"));
        int result = (new NoticeDao()).delete(NoticeId);
        if (result > 0) {
            resp.sendRedirect("notice.jsp");
        }else {
            req.setAttribute("msg","删除失败");
            req.setAttribute("url","notice.jsp");
            req.getRequestDispatcher("WEB-INF/error.jsp").forward(req, resp);
        }
    }
}
